/*
 * Copyright 2009 SHOP.COM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.shop.opensocial.mediated.shindig.factories;

import com.shop.opensocial.mediated.types.AccountMediator;
import com.shop.opensocial.mediated.types.AddressMediator;
import com.shop.opensocial.mediated.types.BodyTypeMediator;
import com.shop.opensocial.mediated.types.ListFieldMediator;
import com.shop.opensocial.mediated.types.NameMediator;
import com.shop.opensocial.mediated.types.OrganizationMediator;
import com.shop.opensocial.mediated.types.PersonMediator;
import com.shop.opensocial.mediated.types.UrlMediator;
import org.apache.shindig.social.core.model.PersonImpl;
import org.apache.shindig.social.opensocial.model.Drinker;
import org.apache.shindig.social.opensocial.model.LookingFor;
import org.apache.shindig.social.opensocial.model.NetworkPresence;
import org.apache.shindig.social.opensocial.model.Person;
import org.apache.shindig.social.opensocial.model.Smoker;
import java.util.Date;
import java.util.List;

/**
 * Factory for converting between Mediator type and Shindig type
 *
 * @author Jordan Zimmerman
 */
public class PersonMediatorFactory extends GenericMediatorFactory<Person, PersonMediator>
{
	public static final GenericMediatorFactoryBase<Person, PersonMediator>		i = new PersonMediatorFactory();

	@Override
	protected Person internalMake(PersonMediator mp)
	{
		Person			p = new PersonImpl();
		
		p.setAboutMe(mp.getAboutMe());
		p.setAccounts(AccountMediatorFactory.i.makeList(mp.getAccounts()));
		p.setActivities(mp.getActivities());
		p.setAddresses(AddressMediatorFactory.i.makeList(mp.getAddresses()));
		p.setAge(mp.getAge());
		p.setBirthday(mp.getBirthday());
		p.setBodyType(BodyTypeMediatorFactory.i.make(mp.getBodyType()));
		p.setBooks(mp.getBooks());
		p.setCars(mp.getCars());
		p.setChildren(mp.getChildren());
		p.setCurrentLocation(AddressMediatorFactory.i.make(mp.getCurrentLocation()));
		p.setDisplayName(mp.getDisplayName());
		p.setDrinker(fDrinkerMapper.toShindig(mp.getDrinker()));
		p.setEmails(ListFieldMediatorFactory.i.makeList(mp.getEmails()));
		p.setEthnicity(mp.getEthnicity());
		p.setFashion(mp.getFashion());
		p.setFood(mp.getFood());
		p.setGender(fGenderMapper.to(mp.getGender(), Person.Gender.male));	// Shindig throws an error if there is no gender
		p.setHappiestWhen(mp.getHappiestWhen());
		p.setHasApp(mp.getHasApp());
		p.setHeroes(mp.getHeroes());
		p.setHumor(mp.getHumor());
		p.setId(mp.getId());
		p.setIms(ListFieldMediatorFactory.i.makeList(mp.getIms()));
		p.setInterests(mp.getInterests());
		p.setIsOwner(mp.getIsOwner());
		p.setIsViewer(mp.getIsViewer());
		p.setJobInterests(mp.getJobInterests());
		p.setLanguagesSpoken(mp.getLanguagesSpoken());
		p.setLivingArrangement(mp.getLivingArrangement());
		p.setLookingFor(fLookingForMapper.toShindigList(mp.getLookingFor()));
		p.setMovies(mp.getMovies());
		p.setMusic(mp.getMusic());
		p.setName(NameMediatorFactory.i.make(mp.getName()));
		p.setNetworkPresence(fNetworkPresenceMapper.toShindig(mp.getNetworkPresence()));
		p.setNickname(mp.getNickname());
		p.setOrganizations(OrganizationMediatorFactory.i.makeList(mp.getOrganizations()));
		p.setPets(mp.getPets());
		p.setPhoneNumbers(ListFieldMediatorFactory.i.makeList(mp.getPhoneNumbers()));
		p.setPhotos(ListFieldMediatorFactory.i.makeList(mp.getPhotos()));
		p.setPoliticalViews(mp.getPoliticalViews());
		p.setProfileSong(UrlMediatorFactory.i.make(mp.getProfileSong()));
		p.setProfileVideo(UrlMediatorFactory.i.make(mp.getProfileVideo()));
		p.setQuotes(mp.getQuotes());
		p.setRelationshipStatus(mp.getRelationshipStatus());
		p.setReligion(mp.getReligion());
		p.setRomance(mp.getRomance());
		p.setScaredOf(mp.getScaredOf());
		p.setSexualOrientation(mp.getSexualOrientation());
		p.setSmoker(fSmokerMapper.toShindig(mp.getSmoker()));
		p.setSports(mp.getSports());
		p.setStatus(mp.getStatus());
		p.setTags(mp.getTags());
		p.setTurnOffs(mp.getTurnOffs());
		p.setTurnOns(mp.getTurnOns());
		p.setTvShows(mp.getTvShows());
		p.setUpdated(mp.getUpdated());
		p.setUtcOffset(mp.getUtcOffset());

		// must be done in this order - I don't know why there are separate methods for thumbnail and profile
		p.setUrls(UrlMediatorFactory.i.makeList(mp.getUrls()));
		p.setThumbnailUrl(mp.getThumbnailUrl());
		p.setProfileUrl(mp.getProfileUrl());
		
		return p;
	}

	@Override
	protected PersonMediator internalUnmake(final Person c)
	{
		return new PersonMediator()
		{
			@Override
			public String getDisplayName()
			{
				return c.getDisplayName();
			}

			@Override
			public String getAboutMe()
			{
				return c.getAboutMe();
			}

			@Override
			public List<AccountMediator> getAccounts()
			{
				return AccountMediatorFactory.i.unmakeList(c.getAccounts());
			}

			@Override
			public List<String> getActivities()
			{
				return c.getActivities();
			}

			@Override
			public List<AddressMediator> getAddresses()
			{
				return AddressMediatorFactory.i.unmakeList(c.getAddresses());
			}

			@Override
			public Integer getAge()
			{
				return c.getAge();
			}

			@Override
			public Date getBirthday()
			{
				return c.getBirthday();
			}

			@Override
			public BodyTypeMediator getBodyType()
			{
				return BodyTypeMediatorFactory.i.unmake(c.getBodyType());
			}

			@Override
			public List<String> getBooks()
			{
				return c.getBooks();
			}

			@Override
			public List<String> getCars()
			{
				return c.getCars();
			}

			@Override
			public String getChildren()
			{
				return c.getChildren();
			}

			@Override
			public AddressMediator getCurrentLocation()
			{
				return AddressMediatorFactory.i.unmake(c.getCurrentLocation());
			}

			@Override
			public Drinker getDrinker()
			{
				return fDrinkerMapper.toMediated(c.getDrinker());
			}

			@Override
			public List<ListFieldMediator> getEmails()
			{
				return ListFieldMediatorFactory.i.unmakeList(c.getEmails());
			}

			@Override
			public String getEthnicity()
			{
				return c.getEthnicity();
			}

			@Override
			public String getFashion()
			{
				return c.getFashion();
			}

			@Override
			public List<String> getFood()
			{
				return c.getFood();
			}

			@Override
			public Gender getGender()
			{
				return fGenderMapper.from(c.getGender());
			}

			@Override
			public String getHappiestWhen()
			{
				return c.getHappiestWhen();
			}

			@Override
			public Boolean getHasApp()
			{
				return c.getHasApp();
			}

			@Override
			public List<String> getHeroes()
			{
				return c.getHeroes();
			}

			@Override
			public String getHumor()
			{
				return c.getHumor();
			}

			@Override
			public String getId()
			{
				return c.getId();
			}

			@Override
			public List<ListFieldMediator> getIms()
			{
				return ListFieldMediatorFactory.i.unmakeList(c.getIms());
			}

			@Override
			public List<String> getInterests()
			{
				return c.getInterests();
			}

			@Override
			public String getJobInterests()
			{
				return c.getJobInterests();
			}

			@Override
			public List<String> getLanguagesSpoken()
			{
				return c.getLanguagesSpoken();
			}

			@Override
			public Date getUpdated()
			{
				return c.getUpdated();
			}

			@Override
			public String getLivingArrangement()
			{
				return c.getLivingArrangement();
			}

			@Override
			public List<LookingFor> getLookingFor()
			{
				return fLookingForMapper.toMediatedList(c.getLookingFor());
			}

			@Override
			public List<String> getMovies()
			{
				return c.getMovies();
			}

			@Override
			public List<String> getMusic()
			{
				return c.getMusic();
			}

			@Override
			public NameMediator getName()
			{
				return NameMediatorFactory.i.unmake(c.getName());
			}

			@Override
			public NetworkPresence getNetworkPresence()
			{
				return fNetworkPresenceMapper.toMediated(c.getNetworkPresence());
			}

			@Override
			public String getNickname()
			{
				return c.getNickname();
			}

			@Override
			public List<OrganizationMediator> getOrganizations()
			{
				return OrganizationMediatorFactory.i.unmakeList(c.getOrganizations());
			}

			@Override
			public String getPets()
			{
				return c.getPets();
			}

			@Override
			public List<ListFieldMediator> getPhoneNumbers()
			{
				return ListFieldMediatorFactory.i.unmakeList(c.getPhoneNumbers());
			}

			@Override
			public List<ListFieldMediator> getPhotos()
			{
				return ListFieldMediatorFactory.i.unmakeList(c.getPhotos());
			}

			@Override
			public String getPoliticalViews()
			{
				return c.getPoliticalViews();
			}

			@Override
			public UrlMediator getProfileSong()
			{
				return UrlMediatorFactory.i.unmake(c.getProfileSong());
			}

			@Override
			public UrlMediator getProfileVideo()
			{
				return UrlMediatorFactory.i.unmake(c.getProfileVideo());
			}

			@Override
			public List<String> getQuotes()
			{
				return c.getQuotes();
			}

			@Override
			public String getRelationshipStatus()
			{
				return c.getRelationshipStatus();
			}

			@Override
			public String getReligion()
			{
				return c.getReligion();
			}

			@Override
			public String getRomance()
			{
				return c.getRomance();
			}

			@Override
			public String getScaredOf()
			{
				return c.getScaredOf();
			}

			@Override
			public String getSexualOrientation()
			{
				return c.getSexualOrientation();
			}

			@Override
			public Smoker getSmoker()
			{
				return fSmokerMapper.toMediated(c.getSmoker());
			}

			@Override
			public List<String> getSports()
			{
				return c.getSports();
			}

			@Override
			public String getStatus()
			{
				return c.getStatus();
			}

			@Override
			public List<String> getTags()
			{
				return c.getTags();
			}

			@Override
			public Long getUtcOffset()
			{
				return c.getUtcOffset();
			}

			@Override
			public List<String> getTurnOffs()
			{
				return c.getTurnOffs();
			}

			@Override
			public List<String> getTurnOns()
			{
				return c.getTurnOffs();
			}

			@Override
			public List<String> getTvShows()
			{
				return c.getTvShows();
			}

			@Override
			public List<UrlMediator> getUrls()
			{
				return UrlMediatorFactory.i.unmakeList(c.getUrls());
			}

			@Override
			public boolean getIsOwner()
			{
				return c.getIsOwner();
			}

			@Override
			public boolean getIsViewer()
			{
				return c.getIsViewer();
			}

			@Override
			public String getProfileUrl()
			{
				return c.getProfileUrl();
			}

			@Override
			public String getThumbnailUrl()
			{
				return c.getThumbnailUrl();
			}
		};
	}

	private static final WrappedEnumMapper<PersonMediator.Drinker, Drinker>					fDrinkerMapper = new WrappedEnumMapper<PersonMediator.Drinker, Drinker>(PersonMediator.Drinker.values(), Drinker.values());
	private static final EnumMapper<PersonMediator.Gender, Person.Gender>					fGenderMapper = new EnumMapper<PersonMediator.Gender, Person.Gender>(PersonMediator.Gender.values(), Person.Gender.values());
	private static final WrappedEnumMapper<PersonMediator.LookingFor, LookingFor>			fLookingForMapper = new WrappedEnumMapper<PersonMediator.LookingFor, LookingFor>(PersonMediator.LookingFor.values(), LookingFor.values());
	private static final WrappedEnumMapper<PersonMediator.NetworkPresence, NetworkPresence>	fNetworkPresenceMapper = new WrappedEnumMapper<PersonMediator.NetworkPresence, NetworkPresence>(PersonMediator.NetworkPresence.values(), NetworkPresence.values());
	private static final WrappedEnumMapper<PersonMediator.Smoker, Smoker>					fSmokerMapper = new WrappedEnumMapper<PersonMediator.Smoker, Smoker>(PersonMediator.Smoker.values(), Smoker.values());

	private PersonMediatorFactory()
	{
	}
}
